/**
 * @file fetch dianping shop information
 * 
 * @author Steve Gao<gaofu@parllay.com>
 */
const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;
const HTTP_STATUSES   = require('../../../constants').HTTP_STATUSES;

/**
 * Fetch dianping shop information
 * 
 * @class FetchShopInfoHandler
 * @extends {BaseHandler}
 */
class FetchShopInfoHandler extends BaseHandler {
    
    get pattern() {
        return "/dianping/shop_info";
    }

    doGET(request, response) {
        if (!request.session.user.authenticated) {
            return response.json({
                success: false,
                error: '请登录系统后使用！'
            });
        }
        if (!request.query.shop_id) {
            return response.json({
                success: false,
                error: '请输入要查询的商家信息！'
            });
        }

        this.Controller.fetchDianpingShopInfo(request.query.shop_id, (data) => {
            response.json({
                success: true,
                data: data
            });
        });
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = FetchShopInfoHandler;